package GUI;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Arrays;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

import Client.Client;

public class GUIFrame extends JFrame implements ActionListener {
	// Variabelbös
	JPasswordField passField;
	JTextField userField;
	Client client;

	public GUIFrame(Client client) {

		super("Journal Handler");
		setVisible(true);
		this.setSize(500, 100);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.client = client;

		setLayout(new GridLayout(3, 2));

		// lägg till saker i listan;
		JLabel userLabel = new JLabel("User:");
		userField = new JTextField("");

		add(userLabel);
		add(userField);

		JLabel passLabel = new JLabel("Password:");
		passField = new JPasswordField(10);

		add(passLabel);
		add(passField);
		add(new JLabel(""));

		JButton button = new JButton("Login");
		add(button);

		pack();

		button.addActionListener(this);

	}

	@Override
	public void actionPerformed(ActionEvent e) {

		// char[] typedPass = passField.getPassword();
		// String s = new String(typedPass);
		//
		// if (userField != null && passField != null) {
		//			
		//
		//			
		//			
		// }
		// Arrays.fill(typedPass, '0');

		client.run("doc1", "ghj58QA1");
		new JournalFrame(client);

		this.setVisible(false);

	}

	public void warningMessage(String s) {
		System.out.print(s);
	}
}
